package graph;

import java.util.Stack;

public class Node{
	Node[] _children;
	Node _parent;
	
	int _numMarks;
	int _id;
	boolean _isGoal;
	
	public Node(int id) {
		_id = id;
		_isGoal = false;
		_numMarks = 0;
	}
	
	public void goal(){
		_isGoal = true;
	}

	public Node() {
	}

	public Node[] getChildren(){
		return _children;
	}
	
	public void setChildren(Node[] children){
		_children = children;
	}
	
	public void setParent(Node parent, int i){
		_parent = parent;
	}
	
	public Node getParent() {
		return _parent;
	}
	
	public boolean isGoal(){
		return _isGoal;
	}
	
	public String toString(){
		return _id+"";
	}
	
	
	public boolean mark(int i){
		if(_numMarks == i){
			_numMarks++;
			return true;
		}
		return false;
	}
	
	public int getNumMarks() {
		return _numMarks;
	}
	
	public int reset(){	//cleans up the graph and returns the total number of nodes visited
		int numMarks = 0;
		Stack<Node> nodes = new Stack<Node>();
		nodes.push(this);
		while (!nodes.isEmpty()){
			Node n = nodes.pop();
			if (n._numMarks>0){
				numMarks+= n._numMarks;
				n._numMarks=0;
				for (int i=0; i<n._children.length;i++){
					nodes.push(n._children[i]);
				}
			}
		}
		return numMarks;
	}
}